package Servlet;

import DAO.ComplaintDAO;
import DAO.DAOFactory;
import javabean.Complaint;
import javabean.Staff;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/pendingComplaint")
public class pendingComplaintServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        HttpSession session = req.getSession();
        Staff loginStaff = (Staff) session.getAttribute("loginStaff");
        ComplaintDAO complaintDAO = (ComplaintDAO) DAOFactory.getComplaintDAOInstance();
        try {
            List<Complaint> ComplaintList = complaintDAO.getAllComplaintByStaffID(loginStaff.getStaffID());
            req.setAttribute("ComplaintList", ComplaintList);
            req.getRequestDispatcher("pendingComplaint.jsp").forward(req, resp);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
